package com.star.dto;

import com.star.enums.StateEnum;
import lombok.Getter;
import lombok.Setter;

/**
 * @Classname Result
 * @Author Star
 * @Date 2021/4/25 - 20:24
 * @Description 封装json对象，所有返回结果都使用它 暂时不用
 */
@Getter
@Setter
public class Result<T> {

    private boolean success;// 是否成功标志

    private T data;// 成功时返回的数据

    private String errorMsg;// 错误信息

    private int state;//状态码

    private String stateInfo;//状态码对应的信息

    public Result() {
    }

    // 成功时的构造器
    public Result(boolean success, StateEnum stateEnum, T data) {
        this.success = success;
        this.data = data;
        this.state=stateEnum.getState();
        this.stateInfo=stateEnum.getStateInfo();
    }
    // 成功时的构造器 成功提示
    public Result(boolean success,String stateInfo) {
        this.success = success;
        this.stateInfo=stateInfo;
    }
    // 错误时的构造器(1)
    public Result(boolean success, int state, String errorMsg) {
        this.success = success;
        this.errorMsg = errorMsg;
        this.state = state;
    }
    // 错误时的构造器(2)
    public Result(boolean success,StateEnum stateEnum) {
        this.success = success;
        this.errorMsg = stateEnum.getStateInfo();
        this.state = stateEnum.getState();
    }

}

